/**************************************************************************
 * $RCSfile: EntitySpecDropDownListener.java,v $  $Revision: 1.2 $  $Date: 2009/07/07 12:58:44 $
 *
 * $Log: EntitySpecDropDownListener.java,v $
 * Revision 1.2  2009/07/07 12:58:44  @author simplefan
 * *** empty log message ***
 *
 * Revision 1.1  2009/01/08 09:32:06  @author simplefan
 * *** empty log message ***
 *
 * Revision 1.1  2009/01/07 08:18:06  @author simplefan
 * add properites show page
 *
 **************************************************************************/
package com.simplefan.meta.determine.client.web.listener;

import java.util.List;

import com.bstek.dorado.data.Dataset;
import com.simplefan.framework.common.dto.query.QueryResult;
import com.simplefan.meta.determine.client.desktop.service.MetaPlatformServiceFacade;

/**
 * @author K
 */
public class EntitySpecDropDownListener extends MetaPlatformListener
{
  @Override
  public void afterLoadData(Dataset dataset) throws Exception {
    super.afterLoadData(dataset);
    MetaPlatformServiceFacade facade = getServiceFacade();
    String name = dataset.parameters().getString("name");
    
    List resultList = null;
    int pageIndex = dataset.getPageIndex();
	int pageSize = dataset.getPageSize();
	int begin = (pageIndex - 1) * dataset.getPageSize();
	int end = pageIndex * dataset.getPageSize() - 1;
	if(name==null ||"".equals(name)){
		QueryResult qResult = facade.getServiceFactory().getMetaPlatformService().findAllBaseEntitySpecs(begin, end);
		resultList = qResult.getPoList();
		long count = qResult.getCount() / pageSize;
		if (qResult.getCount() % pageSize > 0) {
			count++;
		}
		dataset.setPossibleRecordCount(qResult.getCount());
		dataset.setPageCount((int) count);
	}else{
		resultList = facade.findEntitySpecsByName(name);
		dataset.setPossibleRecordCount(resultList.size());
		dataset.setPageCount(resultList.size());
	}
    dataset.fromDO(resultList);
  }

}
